package producersConsumersTests.utils;

import prod_cons.TaskContainer;

public class Remover implements Runnable {
	TaskContainer container;
	volatile boolean stop = false;

	public Remover(TaskContainer container) {
		this.container = container;
	}
	
	public final void stop() {
		this.stop = true;
	}

	@Override
	public final void run() {
		beforeRemoverRun();
		container.registerConsumer();
		while (!stop) {
			beforeGetAttempt();
			Runnable task = container.get();
			afterGetAttempt(task);
		}
		afterRemoverRun();
	}

	protected void beforeRemoverRun() {
	}

	protected void afterRemoverRun() {
	}

	protected void beforeGetAttempt() {
	}

	protected void afterGetAttempt(Runnable task) {
	}
}
